<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <BasicTable @register="registerTable" :searchInfo="searchInfo">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'action'">
          <TableAction
            :actions="[
              // {
              //   label: t('sys.script.details'),
              //   tooltip: '详细信息',
              //   onClick: handleView.bind(null, record),
              // },
              {
                label: t('sys.configuration.delete'),
                color: 'error',
                tooltip:  t('sys.configuration.deleteMsg'),
                popConfirm: {
                  title: t('sys.configuration.IsDelete'),
                  placement: 'left',
                  confirm: handleDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </template>
    </BasicTable>
  </PageWrapper>
</template>
<script lang="ts" setup>
  import { reactive, ref, computed } from 'vue';
  import { message } from 'ant-design-vue';
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { getlistAPI, dataDeleteAPI } from '@/api/demo/video';
  import { PageWrapper } from '@/components/Page';
  import { columns, searchFormSchema } from './account.data';
  import { useGo } from '@/hooks/web/usePage';
  import { useI18n } from "@/hooks/web/useI18n";

  const { t } = useI18n();
  defineOptions({ name: 'AccountManagement' });
  const total = ref(0);

  const tableTitle = computed(() => `${t('sys.video.title')} ${t('sys.configuration.common')} ${total.value} ${t('sys.configuration.strip')}`);
  const go = useGo();
  const searchInfo = reactive<Recordable>({});
  const [registerTable, { reload }] = useTable({
    title: tableTitle,
    api: async (params) => {
      const result = (await getlistAPI(params)) as { items: any[]; total: number };
      total.value = result.total;
      return result;
    },
    rowKey: 'id',
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
      autoSubmitOnEnter: true,
    },
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    actionColumn: {
      width: 120,
      title: t('sys.configuration.action'),
      dataIndex: 'action',
    },
  });

  async function handleDelete(record: Recordable) {
    await dataDeleteAPI({ id: record.id });
    message.success('操作完成');
    reload();
  }

  function handleView(record: Recordable) {
    go('/system/account_detail/' + record.id);
  }
</script>
